package com.shop.cereshop.business.param.business;

import cn.hutool.core.util.StrUtil;
import com.shop.cereshop.business.param.user.UserUpdatePhoneParam;
import com.shop.cereshop.commons.config.RsaProperties;
import com.shop.cereshop.commons.utils.RsaUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @description: TODO
 * @author lx
 * @date 2025/11/24 11:11
 * @version 1.0
 */
@Data
@ApiModel(value = "UpdatePhoneDTO", description = "更新手机号请求实体")
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UpdatePhoneDTO {
    @ApiModelProperty(value = "对象类型 1-商家，2-店铺", required = true)
    @NotNull(message = "对象类型不能为空")
    private Integer type;

    @ApiModelProperty(value = "旧手机验证码", required = true)
    @NotBlank(message = "旧手机验证码不能为空")
    private String oldPhoneCode;

    @ApiModelProperty(value = "新手机验证码", required = true)
    @NotBlank(message = "新手机验证码不能为空")
    private String newPhoneCode;

    @ApiModelProperty(value = "新手机号", required = true)
    @NotBlank(message = "新手机号不能为空")
    private String newPhone;

    @ApiModelProperty(value = "店铺ID 业务字段无需传参")
    private Long shopId;

    @ApiModelProperty(value = "商家ID 业务字段无需传参")
    private Long businessUserId;

    @ApiModelProperty(value = "旧手机号 业务字段无需传参")
    private String oldPhone;

    public UpdatePhoneDTO decrypt() throws Exception {
        UpdatePhoneDTO res = new UpdatePhoneDTO();
        if (StrUtil.isNotBlank(this.oldPhoneCode)) {
            res.setOldPhoneCode(this.oldPhoneCode);
        }
        if (StrUtil.isNotBlank(this.newPhoneCode)) {
            res.setNewPhoneCode(this.newPhoneCode);
        }
        if (StrUtil.isNotBlank(this.newPhone)) {
            res.setNewPhone(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,this.newPhone));
        }
        return res;
    }
}
